package cn.bdqn.asecu.controller;

import cn.bdqn.asecu.service.ProvincialService;
import cn.bdqn.asecu.utility.Utility_Provincial;
import cn.bdqn.asecu.utility.Utility_ru;
import cn.bdqn.pojo.Audit;
import cn.bdqn.pojo.Department;
import cn.bdqn.pojo.Role;
import cn.bdqn.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class ProvincialController {

    @Resource
    private ProvincialService provincialService;

    @RequestMapping("product-list")
    public String productlist(){
        return "product-list";
    }

    @RequestMapping("auditDate")
    @ResponseBody
    public List<Audit> auditDate(){
        return provincialService.audit_id();
    }

    @RequestMapping("DepartmentDate")
    @ResponseBody
    public List<Department> DepartmentDate(){
        return provincialService.Sel_Department_data();
    }

    @RequestMapping("departmentalUsers")
    @ResponseBody
    public List<Utility_Provincial> departmentalUsers(int id,int bid){
        return provincialService.departmentalUsers(id,bid);
    }

    @RequestMapping("beishen-add")
    public String beishenadd(int id, Model model){
        Audit audit = provincialService.Selaudit_id(id);
        model.addAttribute("mid",audit);
        return "beishen-add";
    }

    @RequestMapping("beishen-edit")
    public String beishenedit(int id, Model model){
        Department seldepa = provincialService.Seldepa(id);
        model.addAttribute("seldepa",seldepa);
        return "beishen-edit";
    }

    @RequestMapping("add_aepartmental")
    @ResponseBody
    public String adddepartmental(Department department, HttpSession session){
        User u= (User) session.getAttribute("user");
        department.setUserId(u.getId());
        department.setCode("ADCD");
        provincialService.depaAdd(department);
        return "true";
    }

    @RequestMapping("editdepar")
    @ResponseBody
    public  String editdepar(Department department){
        provincialService.depaAdd(department);
        return "true";
    }

    @RequestMapping("delbmpar")
    @ResponseBody
    public String  deldepar(int id){
        provincialService.delremove(id);
        return "true";
    }

    @RequestMapping("role-list")
    public String roleList(){
        return "role-list";
    }

    @RequestMapping("role_user")
    @ResponseBody
    public List<Utility_ru> role_user(int id){
        return provincialService.Selrole_user(id);
    }

    @RequestMapping("Sel_roleAll")
    @ResponseBody
    public List<Role> Sel_roleAll(){
        return provincialService.Sel_role();
    }

    @RequestMapping("role-add")
    public String roleadd(){
        return "role-add";
    }

    @RequestMapping("role-edit")
    public String roleedit(int id,Model model){
        Role role = provincialService.SelIdrole(id);
        model.addAttribute("roleX",role);
        return "role-edit";
    }

    @RequestMapping("add_role")
    @ResponseBody
    public String add_role(Role role){
        provincialService.add_role(role);
        return "true";
    }

    @RequestMapping("upl_role")
    @ResponseBody
    public String upl_role(Role role){
     provincialService.add_role(role);
     return "true";
    }

}
